def save_files(boy, girl, counts):
    with open('D:/boy_' + str(counts) + '.txt', 'w') as boy_file:
        boy_file.writelines(boy)
    with open('D:/girl_' + str(counts) + '.txt', 'w') as girl_file:
        girl_file.writelines(girl)
    print('任务完成。')


def split_files(file):
    f = open(file)
    boy_says = []
    girl_says = []
    count = 1

    for echo_line in f:
        if echo_line[:4] != '====':
            roles, line_spoken = echo_line.split(':', 1)
            if roles == '小甲鱼':
                boy_says.append(line_spoken)
            if roles == '小客服':
                girl_says.append(line_spoken)
        else:
            save_files(boy_says, girl_says, count)

            boy_says = []
            girl_says = []
            count += 1
    save_files(boy_says, girl_says, count)


split_files('D:/record.txt')
